package com.lb.shopguide.ui.fragment.guide.order;

import android.support.v4.view.ViewPager;
import android.view.View;

import com.flyco.tablayout.SlidingTabLayout;
import com.lb.shopguide.R;
import com.lb.shopguide.adapter.viewpager.AdapterOrderType;
import com.lb.shopguide.base.BaseCommonFragment;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.order.OrderTypeBean;
import com.lb.shopguide.ui.view.NormalTitleBar;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * Created by kang on 2017/6/2.
 */

public class FragmentOrderManager extends BaseCommonFragment {
    @BindView(R.id.ntb)
    NormalTitleBar ntb;
    @BindView(R.id.tabs)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.viewPager)
    ViewPager mViewPager;

    private List<OrderTypeBean> mOrderTypeList;
    private AdapterOrderType mAdapterOrderType;




    public static FragmentOrderManager newInstance() {
        return new FragmentOrderManager();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_order_manager;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        ntb.setTitleText("订单管理");
        ntb.setLeftImageSrc(R.drawable.iv_back);
        ntb.setOnLeftImageListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop();
            }
        });

        bindType();
    }

    @Override
    public void finishRefresh() {

    }

    @Override
    public void sessionOutOfDate() {

    }

    @Override
    public void requestError(String error) {

    }

    @Override
    public String getPageTag() {
        return FragmentOrderManager.class.getName();
    }

    private void bindType() {
        initOrderType();

        mAdapterOrderType = new AdapterOrderType(getChildFragmentManager(), mOrderTypeList);
        mViewPager.setAdapter(mAdapterOrderType);
        mViewPager.setOffscreenPageLimit(4);
        mTabLayout.setViewPager(mViewPager);
    }

    private void initOrderType() {
        mOrderTypeList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            OrderTypeBean item = new OrderTypeBean();
            switch (i) {
                case AppConstant.ORDER_STATUS_ALL:
                    item.setTypeName("全部");
                    break;
                case AppConstant.ORDER_STATUS_NO_PAY:
                    item.setTypeName("待支付");
                    break;
                case AppConstant.ORDER_STATUS_NO_DELIVER:
                    item.setTypeName("待发货");
                    break;
                case AppConstant.ORDER_STATUS_NO_RECEIVE:
                    item.setTypeName("已发货");
                    break;
                case AppConstant.ORDER_STATUS_NO_PICKUP:
                    item.setTypeName("待自提");
                    break;
                case AppConstant.ORDER_STATUS_FINISHED:
                    item.setTypeName("已完成");
                    break;
            }
            item.setTypeCode(i);
            mOrderTypeList.add(item);
        }
    }

//        for (int i = 0; i < mAdapterOrderType.getCount(); i++) {
//            FragmentOrderList fragmentOrderList = (FragmentOrderList) mAdapterOrderType.getItem(i);
//            fragmentOrderList.refresh();
//        }
//    }


}
